package com.powernode.ssm.controller;

import com.powernode.ssm.bean.Vip;
import com.powernode.ssm.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class VipController {

    @Autowired
    private VipService vipService;

    @GetMapping("/detail/{cn}")
    public Vip detail(@PathVariable("cn") String cardNumber){
        return vipService.findByCardNumber(cardNumber);
    }

    @GetMapping("/byid/{id}")
    public Vip byid(@PathVariable("id") Long id){
        return vipService.findById(id);
    }

    @GetMapping("/addvip/{name}/{cardNumber}/{birth}")
    public String addvip(@PathVariable("name") String name,
                       @PathVariable("cardNumber") String cardNumber,
                       @PathVariable("birth") String birth) {
        vipService.add(name,cardNumber,birth);
        return "添加成功";
    }

    @GetMapping("/delete/{id}")
    public String deletevip(@PathVariable("id") Long id){
        vipService.delete(id);
        return "删除成功";
    }

    @GetMapping("/findAll")
    public List<Vip> findAll(){
        return vipService.findAll();
    }
}
